home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / ip / nfs / nfstrace.shar.Z / nfstrace.shar / pfilt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-06  |  1.7 KB  |  96 lines

  1. #include<sys/types.h>
  2. #include<sys/socket.h>
  3. #include <rpc/rpc.h>
  4. #include<net/if.h>
  5. #include<netinet/in_systm.h>
  6. #include<netinet/in.h>
  7. #include<netinet/ip.h>
  8. #include<netinet/udp.h>
  9. #include<netinet/if_ether.h>
  10. #include<rpc/types.h>
  11. #include<sys/param.h>
  12. #include<sys/time.h>
  13. #include <sys/file.h>
  14. #include <sys/errno.h>
  15. #include <sys/ioctl.h>
  16.  
  17. #include <signal.h>
  18. #include<netdb.h>
  19. #include "rpcspy.h"
  20. #include <stdio.h>
  21. #define RES 1    /* tick every second */
  22.  
  23.  
  24. int dropped=0;
  25. int pr=0;
  26. extern int ok, call, fgc;
  27. long secs;    /* current time in secs */
  28. int ser;    /* packets this second */
  29. int clk();
  30. int die();
  31.  
  32. struct enfilter filt = {
  33.     10, 4,
  34.     ENF_PUSHWORD + 6,
  35.     ENF_PUSHLIT, 0x0008,
  36.     ENF_EQ
  37. };
  38.  
  39.  
  40. char pint[64];
  41.  
  42. net_open(interface)
  43.      char *interface;
  44. {
  45.     int efd;
  46.     unsigned short bits;
  47.     int one=1;
  48.     unsigned int back=32;
  49.  
  50.     if ((efd=pfopen(interface,O_RDONLY)) <0) {
  51.         return(efd);
  52.     }
  53.     strcpy(pint,interface);
  54.     /* install filter */
  55.     if (ioctl(efd,EIOCSETF,&filt)<0)
  56.         return -1;
  57.     /*these fail if not root. thats ok */
  58.     ioctl(efd,EIOCALLOWPROMISC,&one);
  59.     ioctl(efd,EIOCALLOWCOPYALL,&one);
  60.  
  61.     ioctl(efd, EIOCSETW, &back);
  62.     bits=ENNONEXCL|ENTSTAMP|ENCOPYALL|ENPROMISC;
  63.     if (ioctl(efd,EIOCMBIS,&bits)<0)
  64.         return -1;
  65.     /* set prom. mode */
  66.         signal(SIGINT, die);
  67.         signal(SIGHUP, die);
  68.     return efd;
  69. }
  70.  
  71. net_read(efd,buf,len)
  72.      int efd;
  73.      ether_packet *buf;
  74.      int len;
  75. {
  76.     int r;
  77.     struct enstamp e;
  78.  
  79.     r=read(efd,buf,len);
  80.     if (r<0)
  81.         return r;
  82.     bcopy(buf,&e,sizeof(struct enstamp));;
  83.     secs=e.ens_tstamp.tv_sec;
  84.     ser=e.ens_tstamp.tv_usec;
  85.     dropped += e.ens_dropped;
  86.     pr++;
  87.     return r;
  88. }
  89.  
  90. die()
  91. {
  92.     printf("\n# flush (processed = %d, dropped = %d, call=%d, ok=%d, fgc=%d)\n",
  93.     pr,dropped,call,ok,fgc);
  94.     exit(0);
  95. }
  96.